import sys,os
from pyfaidx import Fasta
from subprocess import call


def format_seq(seq, wrap):
    seq = seq.upper()
    chunks = [seq[i:i+wrap] for i in range(0, len(seq), wrap)]
    return "\n".join(chunks) + "\n"


fasta1 = Fasta(sys.argv[1])
fasta2 = Fasta(sys.argv[2])

keys = fasta1.keys()


for i in keys:
    out1 = open(f"{i}1.fasta", "w")
    out2 = open(f"{i}2.fasta", "w")
    seq1 = str(fasta1[i][0:].seq)
    seq2 = str(fasta2[i][0:].seq)
    out1.write(">" + i + "\n" + format_seq(seq1, 60))
    out2.write(">" + i + "\n" + format_seq(seq2, 60))
    out1.close()
    out2.close()
    sam = f"{i}.sam"
    cmd = f"minimap2 -ax asm5 -t 10 --eqx {i}1.fasta {i}2.fasta -o {sam}"
    print(cmd)
    #call(cmd, shell=True)
    

    
    
    